<?php
/*
 *      _______ _     _       _     _____ __  __ ______
 *     |__   __| |   (_)     | |   / ____|  \/  |  ____|
 *        | |  | |__  _ _ __ | | _| |    | \  / | |__
 *        | |  | '_ \| | '_ \| |/ / |    | |\/| |  __|
 *        | |  | | | | | | | |   <| |____| |  | | |
 *        |_|  |_| |_|_|_| |_|_|\_\\_____|_|  |_|_|
 */
/*
 *     _________  ___  ___  ___  ________   ___  __    ________  _____ ______   ________
 *    |\___   ___\\  \|\  \|\  \|\   ___  \|\  \|\  \ |\   ____\|\   _ \  _   \|\  _____\
 *    \|___ \  \_\ \  \\\  \ \  \ \  \\ \  \ \  \/  /|\ \  \___|\ \  \\\__\ \  \ \  \__/
 *         \ \  \ \ \   __  \ \  \ \  \\ \  \ \   ___  \ \  \    \ \  \\|__| \  \ \   __\
 *          \ \  \ \ \  \ \  \ \  \ \  \\ \  \ \  \\ \  \ \  \____\ \  \    \ \  \ \  \_|
 *           \ \__\ \ \__\ \__\ \__\ \__\\ \__\ \__\\ \__\ \_______\ \__\    \ \__\ \__\
 *            \|__|  \|__|\|__|\|__|\|__| \|__|\|__| \|__|\|_______|\|__|     \|__|\|__|
 */
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace Home\Controller;
use Common\Controller\HomebaseController; 
/**
 * 市场
 */
class MarketController extends HomebaseController {
	
    //营销课堂
	public function lesson() {
		$lesson_term_id = C('LESSON_TERM_ID');
		if(!$lesson_term_id){
			$lesson_term_id = M('terms')->where(['name'=>'营销课堂'])->getField('term_id');
		}
		$this->assign('lesson_term_id',$lesson_term_id);
		$this->display();
    }
	//获取营销课堂的分类
	public function get_lesson_cat(){
		$_tid = M('Terms')->where(['name'=>'营销课堂'])->getField('term_id');
		$cats = M('Terms')->where(['parent'=>$_tid])->select();
		if(!empty($cats)){
			$cats['status'] = 1;
		}
		$this->ajaxReturn($cats);
	}
	//根据分类获取营销课堂的内容
	public function get_lesson_by_cat(){
		$lesson_term_id = C('LESSON_TERM_ID');
		if(!$lesson_term_id){
			$lesson_term_id = M('terms')->where(['name'=>'营销课堂'])->getField('term_id');
		}
		$term_id = I('term_id',$lesson_term_id);
		$order = I('order','posts.post_modified');
		$page_size = I('page_size',6);
		$lessons=sp_sql_posts_paged_bycatid($term_id,"field:post_title,post_excerpt,object_id,smeta,term_id,post_hits,post_date,post_content;order:$order desc;",$page_size);
		//$this->ajaxReturn($lessons);
		$posts = array();
		foreach($lessons['posts'] as $post){
			$post['detail'] = leuu('article/index',array('id'=>$post['object_id'],'cid'=>$post['term_id']));
			$post['smeta'] = json_decode($post['smeta'],true);
			$post['smeta']['thumb'] = sp_get_asset_upload_path($post['smeta']['thumb']);
			$posts[] = $post;
		}
		if(!empty($posts)){
			$lessons['posts'] = $posts;
			$lessons['status'] = 1;
		}
		$this->ajaxReturn($lessons);
	}

}


